package com.cn.xly2023.controller;

import com.cn.xly2023.pojo.User;
import com.cn.xly2023.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@Api(value = "用户数据test",tags = "用户数据接口API")
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/test01",method = RequestMethod.GET)
    @ApiOperation(value = "user test01",notes = "测试方法")
    public String test01() {
        return userService.test01();
    }
    @RequestMapping(value = "/select",method = RequestMethod.GET)
    @ApiOperation(value = "user selectById",notes = "从数据库查询记录")
    public Map<String,Object> selectById(Integer id){
        return userService.selectById(id);

    }

    @RequestMapping(value = "selectAll",method = RequestMethod.GET)
    public Map<String,Object> selectAll(){
        return userService.selectAll();

    }


    @RequestMapping(value = "selectByPage",method = RequestMethod.GET)
    public Map<String,Object> selectByPage(@RequestParam Integer page,@RequestParam Integer limit,String username,Integer age){
        return userService.selectByPage(page,limit,username,age);

    }

    @RequestMapping(value = "insert",method = RequestMethod.POST)
    public Map<String,Object> insert(@RequestBody User user){
        return userService.insert(user);

    }


    @RequestMapping(value = "updateById",method = RequestMethod.POST)
    public Map<String,Object> insert(@RequestParam Integer id,@RequestParam Integer age) {
        return userService.updateById(id,age);
    }

    @RequestMapping(value = "deleteById",method = RequestMethod.POST)
    public Map<String,Object> delete(@RequestParam Integer id){
        return userService.deleteById(id);}

    @RequestMapping(value = "login",method = RequestMethod.POST)
    public Map<String,Object> delete(@RequestParam String username,@RequestParam String password){
        return userService.login(username, password);}
}


